<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    console.log(1111111)

    function f(total, size, page, btnCount) {
      // show me your code
      const arr = [] // 能看到的页码集合
      const pagenum = page - Math.floor(btnCount / 2)
      for (let i = 0; i < btnCount; i++) {
        if (pagenum < 0) {
          arr[i] = page + i
        } else if (pagenum > 0) {
          arr[i] = page - Math.floor(btnCount / 2) + i //5+0  5+1 5+2 5+3 5+4 
        } else {
          arr[i] = page - Math.floor(btnCount / 2) + i + 1
        }
      }
      return arr
    }
    console.log(f(100, 10, 1, 5))
    // 在可能的情况下，让page处于正中间
    // ==> [1, 2, 3, 4, 5]
    // f(100, 10, 7, 5) // ==> [5, 6, 7, 8, 9]
    // f(100, 10, 2, 5) // ==> [1, 2, 3, 4, 5]
    // f(100, 10, 5, 5) // ==> [3, 4, 5, 6, 7]

  </script>
</body>

</html>
